﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmallTfs
{
    public class TFSFolder
    {
        private List<TFSFolder> childFolders = new List<TFSFolder>();

        public List<TFSFolder> ChildFolders
        {
            get { return childFolders; }
            set { 
            
                childFolders = value;

                var tmpChild = childFolders;

                childFolders = new List<TFSFolder>();

                List<TFSFolder> retList = new List<TFSFolder>();
                
                while (true)
                {
                    if (tmpChild.Count == 0)
                        break;

                    TFSFolder fld = tmpChild[0];

                    tmpChild.Remove(fld);

                    List<TFSFolder> tmpList = (from f1 in tmpChild
                                               where f1.Path.Contains(fld.Path)
                                               select f1).ToList();

                    tmpChild.RemoveAll(x => x.Path.Contains(fld.Path));

                    fld.ChildFolders = tmpList;

                    childFolders.Add(fld);
                }
            
            
            
            
            
            }
        }
        public string Name
        {

            get
            {
                return Path.Substring(Path.LastIndexOf('/')+1, Path.Length - Path.LastIndexOf('/') -1);

            }

        }
        public string Path { get; set; }

    }
}
